package com.itheima.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mapper.EmproleMapper;
import com.itheima.mapper.PermissionMapper;
import com.itheima.mapper.RolePermissionMapper;
import com.itheima.pojo.Permission;
import com.itheima.pojo.RolePermission;
import com.itheima.service.RolePermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

@Service
public class RolePermissionServiceImpl extends ServiceImpl<RolePermissionMapper, RolePermission> implements RolePermissionService {
    @Autowired
    private RolePermissionMapper rolePermissionMapper;
    @Autowired
    private PermissionMapper permissionMapper;
    public List<Integer> listPermissionIdsByRoleIds(List<Integer> roleIds) {
        LambdaQueryWrapper<RolePermission> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(RolePermission::getRoleId, roleIds);
        return rolePermissionMapper.selectList(queryWrapper).stream()
                .map(RolePermission::getPermissionId)
                .filter(permissionId -> {
                    // 查询权限状态是否为启用
                    Permission permission = permissionMapper.selectById(permissionId);
                    return permission != null && permission.getEnVisible() == 1;
                })
                .collect(Collectors.toList());
    }
}
